package com.exam.examtest.activity

import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.exam.examtest.R
import com.exam.examtest.util.ActivityStack
import com.exam.examtest.util.ToastUtil
import com.gyf.barlibrary.ImmersionBar

/**
 * ClassName BaseActivity
 * Create by rhf
 * Create on 2021/3/30 11:49
 * Description 基类Activity
 */
@SuppressLint("Registered")
open class BaseActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ImmersionBar.with(this)
            .fitsSystemWindows(true)
            .statusBarColor(R.color.color_197bff)
            .init()
        ActivityStack.getInstance().addActivity(this)
    }

    override fun onDestroy() {
        super.onDestroy()

        ActivityStack.getInstance().removeActivity(this)
    }

    /**
     * 弹出短时吐司
     */
    fun showShortToast(message: String) {
        ToastUtil.showShortToast(this, message)
    }

    /**
     * dip转换为px
     */
    fun dip2Px(mContext: Context, dip: Int): Int {
        /*
        1.  px/(ppi/160) = dp
        2.  px/dp = density
         */
        //取得当前手机px和dp的倍数关系
        val density = mContext.resources.displayMetrics.density
        return (dip * density + .5f).toInt()
    }
}